/**
 * 2025/01/01 - 2025/12/31
 */
package com.snail.server.database.engine.ddl.index.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.snail.server.database.engine.ddl.index.entity.Index;
import com.snail.server.database.engine.ddl.index.entity.IndexFieldMapping;
import com.snail.server.database.engine.ddl.index.mapper.IndexFieldMappingMapper;
import com.snail.server.database.engine.ddl.index.mapper.IndexMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 * @author zgadmin
 * @date 2025/8/29 14:44
 *
 */
@Service
public class IndexService extends ServiceImpl<IndexMapper, Index> {

    @Resource
    IndexFieldMappingMapper indexFieldMappingMapper;

    public boolean dropTable(Long tableId){
        remove(Wrappers.lambdaQuery(Index.class).eq(Index::getTableId, tableId));
        return indexFieldMappingMapper.delete(Wrappers.lambdaQuery(IndexFieldMapping.class).eq(IndexFieldMapping::getTableId, tableId)) >= 1;
    }

    public List<Index> queryByTable(Long tableId) {
        return list(Wrappers.lambdaQuery(Index.class).eq(Index::getTableId, tableId));
    }
}
